<?php

namespace App\Http\Controllers\Mobile;

use App\Interfaces\GoodsService;
use App\Interfaces\ShopService;
use App\Interfaces\UserCollectionService;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class ShopController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index($id,Request $request,ShopService $shopService,UserCollectionService $collectionService,GoodsService $goodsService)
    {
        //$shop = $shopService->get($id);
        //$page = $request->get('page');
        $shopCollectionStatus = 0;
        $user = Auth::user();
        if($user){
            $user_id = $user->id;
            $userCollection = $collectionService->isInCollection($user_id,"SHOP",$id);
            if($userCollection){
                $shopCollectionStatus = 1;
            }
        }
        $goods = array();
        $goods = $goodsService->getGoodsByShop($id,1)->toArray();
        $shop = $shopService->get($id);

        if(!$shop){
            return view('errors.mobile404');
        }

        return view('mobile.shop.index',compact('shop','goods','shopCollectionStatus'));
    }

    public function getShopGoods(Request $request,GoodsService $goodsService)
    {
        $shop_id = $request->get('shop_id');
        $page = $request->get('page');
        $goods = $goodsService->getGoodsByShop($shop_id,$page)->toArray();
        return response()->json(['goods'=>$goods,'status'=>'1']);
    }


}
